package com.sise.controller;


import com.sise.pojo.Dept;
import com.sise.pojo.Emp;
import com.sise.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 彭海霞
 * @since 2020-06-10
 */
@Controller
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;
    @RequestMapping("/selectDeptAll")
    public String selectDeptAll(Model model) {
        //  参数一：当前页
        //  参数二：页面大小
        //  使用了分页插件之后，所有的分页操作也变得简单的！
        List<Dept> list = deptService.list(null);
        model.addAttribute("list", list);
        return "dept-list";
    }
    @RequestMapping("/addDept")
    public String addEmp(Dept dept,Model model) {
        System.out.println("进来了");
        boolean save = deptService.save(dept);
        return "forward:/dept/selectDeptAll";
    }
    @RequestMapping("/selectDeptById")
    public String selectDeptById( Long id, Model model) {
        Dept dept = deptService.getById(id);
        model.addAttribute("dept", dept);
        return "dept-view";
    }
    @RequestMapping("/updateDept")
    public String updateDept(Dept dept) {
        boolean b = deptService.updateById(dept);
        return "forward:/dept/selectDeptAll";
    }
    @RequestMapping("/deleteDeptById")
    public String deleteDeptById(Long id) {
        boolean b = deptService.removeById(id);
        return "forward:/dept/selectDeptAll";
    }
}

